const shopmodle = require('../../modle/shopper')
const shopperusermodel = require('../../modle/shopperuser')
const { Op } = require('sequelize')
module.exports = {
    async getshop(offset, limit, id, titname, pername, phone, time, address, status) {
        if (status == 3) {
            return await shopmodle.findAndCountAll({
                where: {
                    id: {
                        [Op.like]: `%${id}%`
                    },
                    dname: {
                        [Op.like]: `%${titname}%`
                    },
                    name: {
                        [Op.like]: `%${pername}%`
                    },
                    phone: {
                        [Op.like]: `%${phone}%`
                    },
                    // createdAt: {
                    //     [Op.like]: `%${time}%`
                    // },
                    address: {
                        [Op.like]: `%${address}%`
                    }
                },
                limit: +limit,
                offset: (+offset - 1) * +limit
            })
        }
        return await shopmodle.findAndCountAll({
            where: {
                id: {
                    [Op.like]: `%${id}%`
                },
                dname: {
                    [Op.like]: `%${titname}%`
                },
                name: {
                    [Op.like]: `%${pername}%`
                },
                phone: {
                    [Op.like]: `%${phone}%`
                },
                // createdAt: {
                //     [Op.like]: `%${time}%`
                // },
                address: {
                    [Op.like]: `%${address}%`
                },
                status: {
                    [Op.like]: `%${+status}%`
                }
            },
            limit: +limit,
            offset: (+offset - 1) * +limit
        })
    }
    , async update(id, data) {
        const rudata = await shopmodle.update({ ...data }, {
            where: {
                id
            }
        })
        return rudata[0]
    },
    async shopperuserupdate(id, data) {
        const rudata = await shopperusermodel.update({
            ...data
        }, {
            where: {
                id
            }
        })
        return rudata[0]
    }
}